﻿Public Class Relance_CTRL
    Implements IDisposable

    Private _EDM As AniFormEntities
    Private _listeRelancable As List(Of LignesConsultations)
    Private _listeARelancer As List(Of LignesConsultations)

#Region "Cycle de vie du controleur Relance"

    Public Sub New(ByVal edm As AniFormEntities)
        'todo : apprendre a faire la bonne requete direct avec link
        _EDM = edm
        _listeRelancable = New List(Of LignesConsultations)
        _listeARelancer = New List(Of LignesConsultations)
        setListeRelance()

    End Sub

    Private disposedValue As Boolean = False        ' Pour détecter les appels redondants

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
            End If

            _EDM.Dispose()
            For Each element In _listeARelancer
                element = Nothing
            Next
            _listeARelancer.Clear()
            _listeARelancer = Nothing
            For Each element In _listeRelancable
                element = Nothing
            Next
            _listeRelancable.Clear()
            _listeRelancable = Nothing
        End If
        Me.disposedValue = True
    End Sub

#End Region





    Public Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

    Private Sub setListeRelance()
        Dim requete As IEnumerable(Of LignesConsultations) = (From uneLigne In _EDM.LignesConsultations _
                                                      Select uneLigne _
                                                      Where uneLigne.RappelEnvoye = False _
                                                      And uneLigne.Baremes.TypeActe = "VACC")
        For Each ligne As LignesConsultations In requete
            Debug.WriteLine(ligne.DateFinValiditeVaccin.ToString & vbCrLf & _
                            Now.ToString & vbCrLf & _
                            DateDiff(DateInterval.Day, Now, ligne.DateFinValiditeVaccin))


            If DateDiff(DateInterval.Day, Now, ligne.DateFinValiditeVaccin) Then '<= 45 Then
                _listeRelancable.Add(ligne)
            End If
        Next
    End Sub

    Public ReadOnly Property getListeRelancable() As List(Of LignesConsultations)
        Get
            Return _listeRelancable
        End Get
    End Property

    Public ReadOnly Property getListeARelancer() As List(Of LignesConsultations)
        Get
            Return _listeARelancer
        End Get
    End Property

    Public Sub AjouterDansListeARelancer(ByVal ligne As LignesConsultations)
        _listeARelancer.Add(ligne)
    End Sub

End Class
